package com.ning.activitys.skysound.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;

import com.ning.activitys.skysound.R;
import com.ning.activitys.skysound.service.PlayService;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by dllo on 16/1/11.
 */
public class StartActivity extends AppCompatActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);

        //在启动页中启动服务,服务启动与绑定在一起的时候,当与服务绑定的Activity销毁的时候,服务被收回,
        //解决方法,先启动服务,然后别的组件在进行绑定
        startService(new Intent(this, PlayService.class));

        final Handler handler = new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
                Intent intent = new Intent(StartActivity.this,MainActivity.class);
                startActivity(intent);
                finish();
                return false;
            }
        });

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000);
                    handler.sendEmptyMessage(0);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    @Override
    protected void onResume() {
        super.onResume();

        JPushInterface.init(this);
        JPushInterface.setDebugMode(true);

    }


}
